package com.usian.controller;

import com.usian.mapper.YuanMapper;
import com.usian.pojo.Yuan;
import com.usian.service.YuanService;
import com.usian.service.ZhanghaoService;
import com.usian.vo.YuanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/yuan")
public class YuanController {
    @Autowired
    private YuanService yuanService;
    @Autowired
    private ZhanghaoService zhanghaoService;

    @RequestMapping("/fin")
    public String findList(Model model) {
        List<YuanVo> list = yuanService.find1();
        model.addAttribute("list",list);
        return "show";
    }

    @RequestMapping("/ad")
    public String hh() {
        return "jia";
    }

    @RequestMapping(value = "/j")
    public String tant(Yuan yuan){
         yuanService.add(yuan);
        return "redirect:/yuan/fin";
    }

    @RequestMapping("/findBy")
    public String findList(Model model,@RequestParam("id") Integer id) {
        Yuan byId = yuanService.findById(id);
        model.addAttribute("list",byId);
        return "update";
    }
    @RequestMapping(value = "/upda")
    public String up(Yuan yuan){
        yuanService.update(yuan);
        return "redirect:/yuan/fin";
    }
    @RequestMapping("/delete")
    public  String del(@RequestParam("id") Integer id){
        yuanService.delete(id);
        return "redirect:/yuan/fin";
    }
}
